﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordFun.Utils;

namespace WordFun.Models
{
    /// <summary>
    /// Class store animation and specifies method of Game Object
    /// </summary>
    public class ModelChar
    {
        //Default value
        public static double DEFAULT_X = 0;
        public static double DEFAULT_Y = 0;
        public static char DEFAULT_CHAR = ' ';

        private char _char; //content of char
        private ControlChar _control; //control of view 
        private Point2D _location;//location on the screen 

        /// <summary>
        /// Default Contructor
        /// </summary>
        public ModelChar()
        {
            Point2D point = new Point2D(DEFAULT_X, DEFAULT_Y);
            Initialize(DEFAULT_CHAR, ref point);
        }

        /// <summary>
        /// Constructor 
        /// </summary>
        /// <param name="charContent">content of char</param>
        /// <param name="location">location on screen</param>
        public ModelChar(char charContent, ref Point2D location)
        {
            Initialize(charContent, ref location);
        }

        /// <summary>
        /// Swap two ModelChar
        /// </summary>
        /// <param name="modelChar">ModelChar object to swap</param>
        public void Swap(ref ModelChar modelChar)
        {
            ////set controls state to SwappingDown
            //this.SetControlState(ControlCharStates.SwappingDown);
            //modelChar.SetControlState(ControlCharStates.SwappingDown);

            //swap location value
            char temp = this.CharContent;
            this.CharContent = modelChar.CharContent;
            modelChar.CharContent = temp;

            this.SetControlState(ControlCharStates.Normal);
            modelChar.SetControlState(ControlCharStates.Normal);
        }

        /// <summary>
        /// Get current ModelChar object state
        /// </summary>
        /// <returns>ControlWordStates</returns>
        public ControlCharStates GetCurrentState() 
        {
            return _control.GetCurrentState(); // return control state    
        }

        /// <summary>
        /// get, set CharContent value
        /// </summary>
        public char CharContent
        {
            get
            {
                return _char; // return value
            }
            set
            {
                _char = value; // set value
                _control.CharContent = _char.ToString();
            }
        }

        /// <summary>
        /// get, set location
        /// </summary>
        public Point2D Location
        {
            get
            {
                return _location; //get location
            }
            set 
            {
                _location.SetXY(value.X, value.Y); //set location
            }
        }

        /// <summary>
        /// Get control Win8
        /// </summary>
        /// <returns></returns>
        public ControlChar GetControl()
        {
            return _control;
        }

        public ControlChar Control {
            get {
                return _control;
            }
            set {
                _control = value;
            }
        }
        /// <summary>
        /// Init deafult value 
        /// </summary>
        /// <param name="charContent">content of char</param>
        /// <param name="location">location on screen (Left,Top)</param>
        private void Initialize(char charContent, ref Point2D location) 
        {
            _char = charContent;
            _location = location;

            InitializeControl();//init ControlWord (view animation)
        }

        /// <summary>
        /// Init ControlWord
        /// </summary>
        private void InitializeControl()
        {
            _control = new ControlChar();// create object
            _control.CharContent = _char.ToString();// set character view
            _control.SetLocation(_location);// set control's location
        }

        /// <summary>
        /// Set ControlWord state
        /// </summary>
        /// <param name="currState">ControlWordStates enum</param>
        private void SetControlState(ControlCharStates currState) 
        {
            _control.SetState(currState); //set control's current state
        }
    }
}
